package com.venue.hjt.venueclass.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.venue.hjt.venueclass.R;
import com.venue.hjt.venueclass.db.VenueHour;

import java.util.List;

/**
 * Created by xqx on 2017/10/25.
 *
 */

public class HomeAdapter extends BaseAdapter {
    private Context mContext;
    private List<VenueHour> list;
    public HomeAdapter(Context mContext, List<VenueHour> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHander viewHander;
        if (convertView==null){
            viewHander=new ViewHander();
            convertView= View.inflate(mContext, R.layout.home_item,null);
            viewHander.ll_home_bg=convertView.findViewById(R.id.ll_home_bg);
            viewHander.tv_time=convertView.findViewById(R.id.tv_time);
            viewHander.tv_venue_y=convertView.findViewById(R.id.tv_venue_y);
            convertView.setTag(viewHander);
        }else{
            viewHander= (ViewHander) convertView.getTag();
        }
        VenueHour hour = list.get(position);
        if (hour.getStatus().equals("1")){
            viewHander.tv_time.setText(hour.getStart_time()+"～"+hour.getEnd_time());
            viewHander.tv_time.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            viewHander.ll_home_bg.setBackgroundResource(R.drawable.shape9);
            viewHander.tv_venue_y.setText("已预约");
            viewHander.tv_venue_y.setTextColor(Color.parseColor("#ffac69"));
        }else{
            viewHander.tv_time.getPaint().setFlags(0);
            viewHander.tv_time.setText(hour.getStart_time()+"～"+hour.getEnd_time());
            viewHander.ll_home_bg.setBackgroundResource(R.drawable.shape8);
            viewHander.tv_venue_y.setText("可预约");
            viewHander.tv_venue_y.setTextColor(Color.parseColor("#000000"));
        }
//        viewHander.ll_home_bg.setBackgroundResource(R.drawable.shape9);
//        viewHander.tv_time.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        return convertView;
    }
    class ViewHander{
        TextView tv_time,tv_venue_y;
        LinearLayout ll_home_bg;
    }


}
